package com.dyz.leetcode._20_dynamicProgramming._746;

public class _746_minCostClimbingStairs03 {
    // 动态规划 + 状态空间压缩
    public int  minCostClimbingStairs(int[] cost) {
        int n = cost.length;
        int prev = 0, curr = 0;
        for (int i = 2; i <= n; i++) {
            int tmp = Math.min(curr + cost[i - 1], prev + cost[i - 2]);
            prev = curr;
            curr = tmp;
        }
        return curr;
    }
}
